package com.kanqiubao.kq.fragment.main;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.angcyo.tablayout.DslTabLayout;
import com.angcyo.tablayout.delegate.ViewPager1Delegate;
import com.kanqiubao.kq.R;
import com.kanqiubao.kq.fragment.BaseFragment;
import com.kanqiubao.kq.fragment.NewsFragmentStatePagerAdapter;
import com.kanqiubao.kq.fragment.video.VideoListFragment;

import java.util.ArrayList;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

public class MainFragmentFour extends BaseFragment {

    private DslTabLayout mDslTabLayout;
    private ViewPager mViewPager;
    private NewsFragmentStatePagerAdapter mNewsFragmentStatePagerAdapter;
    private ArrayList<Fragment> mListFragments;

    @Override
    protected int getLayoutId() {
        return R.layout.main_fragment_four_layout;
    }

    @Override
    protected void initView() {
        mDslTabLayout = (DslTabLayout) findView(R.id.video_tab_id);
        mViewPager = (ViewPager) findView(R.id.video_page_id);
        initFragment();
    }

    @Override
    protected void initData() {

    }

    private void initFragment() {
        mNewsFragmentStatePagerAdapter = new NewsFragmentStatePagerAdapter(getChildFragmentManager());
        mListFragments = new ArrayList<>();
        VideoListFragment item1 = new VideoListFragment();
        item1.setmTitle("全部");
        VideoListFragment item2 = new VideoListFragment();
        item2.setmTitle("英超");
        VideoListFragment item4 = new VideoListFragment();
        item4.setmTitle("西甲");
        VideoListFragment item5 = new VideoListFragment();
        item5.setmTitle("德甲");
        VideoListFragment item6 = new VideoListFragment();
        item6.setmTitle("意甲");
        VideoListFragment item7 = new VideoListFragment();
        item7.setmTitle("CBA");
        VideoListFragment item8 = new VideoListFragment();
        item8.setmTitle("欧冠");
        VideoListFragment item9 = new VideoListFragment();
        item9.setmTitle("中超");
        VideoListFragment item10 = new VideoListFragment();
        item10.setmTitle("欧洲杯");
        mListFragments.add(item1);
        mListFragments.add(item2);
        mListFragments.add(item4);
        mListFragments.add(item5);
        mListFragments.add(item6);
        mListFragments.add(item7);
        mListFragments.add(item8);
        mListFragments.add(item9);
        mListFragments.add(item10);
        for (int i = 0; i < mListFragments.size(); i++) {
            View v = LayoutInflater.from(getActivity()).inflate(R.layout.recoding_layout_txt_view, null);
            ((TextView) v.findViewById(R.id.text_view)).setText(((BaseFragment) mListFragments.get(i)).getmTitle());
            mDslTabLayout.addView(v);
        }
        mNewsFragmentStatePagerAdapter.setData(mListFragments);
        mViewPager.setAdapter(mNewsFragmentStatePagerAdapter);
        ViewPager1Delegate viewPager1Delegate = new ViewPager1Delegate(mViewPager, mDslTabLayout);
        mDslTabLayout.setupViewPager(viewPager1Delegate);
    }
}